const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pswType: true,
    ifShowPsw: 'hide'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      member_unionid: decodeURI(options.member_unionid),
      member_info: decodeURI(options.member_info),
      username: decodeURI(options.username),
      phone: decodeURI(options.phone),
      share_key: decodeURI(options.share_key),
      avatarUrl: decodeURI(options.avatarUrl),
    })
  },
  changeifShowPsw: function (e) {
    var type = e.currentTarget.dataset.type;
    this.setData({
      ifShowPsw: type
    })
    if (this.data.ifShowPsw == 'hide') {
      this.setData({
        pswType: true
      })
    } else {
      this.setData({
        pswType: false
      })
    }
  },
  password: function (e) {
    this.setData({
      password: e.detail.value
    })
  },
  register: function () {
    console.log(this.data);

    //member_unionid=ob8vQ1LjwEDfqxlHXZufNDjk8628
    //&member_info=FANS
    //&username=FANS
    //&phone=18907238629
    //&share_key=
    //&avatarUrl=https%3A%2F%2Fwx.qlogo.cn%2Fmmopen%2Fvi_32%2FQ0j4TwGTfTLOMFSAg7ZEtybjatVYJYkPicRWssGAnMHc1oRichaYhx1mMmhJ278BQU7NdtDJqBc4RVPvqbGP8mpA%2F132
    var self = this;
    if (self.data.password && self.data.password.trim().length >= 6) {
      wx.request({
        url: app.globalData.ApiUrl + '/index.php?act=connect&op=set_member_pwd',
        data: {
          client: 'wechat',
          type: 'wx',
          member_unionid: self.data.member_unionid,
          member_info: self.data.member_info,
          username: self.data.username,
          phone: self.data.phone,
          password: self.data.password,
          share_key: self.data.share_key,
          avatarUrl: self.data.avatarUrl
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'POST',
        success: (res) => {
          wx.setStorage({
            key: 'key',
            data: res.data.datas.key
          })
          wx.setStorage({
            key: 'username',
            data: res.data.datas.username
          })
          setTimeout(function () {
            wx.switchTab({
              url: '../member/member'
            })
          }, 200)
          wx.showLoading({
            title: '登录中',
          })
        }
      });
    } else {
      wx.showToast({
        title: '请至少输入6位数密码',
        icon: 'none'
      })
    }

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})